package com.atguigu.gmall.realtime.app.udf;

import com.atguigu.gmall.realtime.utils.KeywordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.util.List;
// 一个词条对应多个单词 应该是UDTF的形式
@FunctionHint(output = @DataTypeHint("ROW<s STRING>"))
public class KeywordUDTF extends TableFunction<Row> {
    public void eval(String value){
        List<String> keywordList = KeywordUtil.analyse(value);
        for(String keyword: keywordList){
            Row row = new Row(1);
            row.setField(0,keyword);
            collect(row);
        }
    }
}
